﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace syc.Store
{
    public class 物料分类查询 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {

            context.Response.CacheControl = "no-cache";
            context.Response.Expires = -1;

            string s = context.Request["s"];
            if (s == null) return;
            int fid;
            if (!int.TryParse(s, out fid))
            {
                return;
            }

            SqlConnection Conn = new SqlConnection();
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
            Conn.Open();
            SqlCommand Cmd = new SqlCommand();
            Cmd.Connection = Conn;
            Cmd.CommandText = "select * from 物料分类 where FID=" + fid;
            Cmd.CommandType = CommandType.Text;
            SqlDataReader Reader = Cmd.ExecuteReader();

            while (Reader.Read())
            {
                if ((byte)Reader["LV"] == 0)
                {
                    context.Response.Write(((int)Reader["ID"]).ToString("D7") + "|1|" + ((int)Reader["ID"]/100000).ToString("D2") + (string)Reader["名称"] + "|/TreeView/lv1.png\n");
                }
                else if ((byte)Reader["LV"] == 1)
                {
                    context.Response.Write(((int)Reader["ID"]).ToString("D7") + "|1|" + (((int)Reader["ID"] % 100000)/1000) .ToString("D2") + (string)Reader["名称"] + "|/TreeView/lv2.png\n");
                }
                else if ((byte)Reader["LV"] == 2)
                {
                    context.Response.Write(((int)Reader["ID"]).ToString("D7") + "|0|" + ((int)Reader["ID"] % 1000).ToString("D3") + (string)Reader["名称"] + "|/TreeView/lv3.png\n");
                }
            }
            Reader.Close();
            Conn.Close();
            Reader.Dispose();
            Cmd.Dispose();
            Conn.Dispose();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
